using System;
using System.Collections;
using System.Collections.Generic;

namespace NFreeMarker.Template
{
    public class EmptyMap<TKey, TValue> : IDictionary<TKey, TValue>// TODO, Cloneable
    {
        public static readonly EmptyMap<TKey, TValue> Instance = new EmptyMap<TKey, TValue>(); 
        
        private readonly IList<TKey> _keys = new List<TKey>().AsReadOnly();
        private readonly IList<TValue> _values = new List<TValue>().AsReadOnly();
        private readonly IList<KeyValuePair<TKey, TValue>> _keysAndValues =
            new List<KeyValuePair<TKey, TValue>>().AsReadOnly();

        public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
        {
            return _keysAndValues.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        public void Add(KeyValuePair<TKey, TValue> item)
        {
            throw new NotSupportedException("This Map is read-only.");
        }

        public void Clear()
        {
            throw new NotSupportedException("This Map is read-only.");
        }

        public bool Contains(KeyValuePair<TKey, TValue> item)
        {
            return false;
        }

        public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
        {
        }

        public bool Remove(KeyValuePair<TKey, TValue> item)
        {
            throw new NotSupportedException("This Map is read-only.");
        }

        public int Count
        {
            get { return 0; }
        }

        public bool IsReadOnly
        {
            get { return true; }
        }

        public bool ContainsKey(TKey key)
        {
            return false;
        }

        public void Add(TKey key, TValue value)
        {
            throw new NotSupportedException("This Map is read-only.");
        }

        public bool Remove(TKey key)
        {
            throw new NotSupportedException("This Map is read-only.");
        }

        public bool TryGetValue(TKey key, out TValue value)
        {
            value = default(TValue);
            return false;
        }

        public TValue this[TKey key]
        {
            get { return default(TValue); }
            set { throw new NotSupportedException("This Map is read-only."); }
        }

        public ICollection<TKey> Keys
        {
            get { return _keys; }
        }

        public ICollection<TValue> Values
        {
            get { return _values; }
        }
    }
}